package com.tedu.pj.goods.controller;

import com.tedu.pj.goods.pojo.Goods;
import com.tedu.pj.goods.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    GoodsService goodsService;

    @RequestMapping("/doUpdateGoods")
    @ResponseBody
    public String doUpdateGoods(Goods goods){
        goodsService.updateGoods(goods);
        return "修改成功";
    }

    @RequestMapping("/doFindByIdGoods")
    @ResponseBody
    public Goods doFindByIdGoods(int id){
        return goodsService.findByIdGoods(id);
    }

    @RequestMapping("/doRemoveByIdGoods")
    @ResponseBody
    public String doRemoveByIdGoods(int id){
        goodsService.removeByIdGoods(id);
        return "删除成功";
    }

    @RequestMapping("/doInsertGoods")
    @ResponseBody
    public String doInsertGoods(Goods goods){
        goodsService.insertGoods(goods);
        return "插入成功";
    }

    @RequestMapping("/doFindGoods")
    @ResponseBody
    public List<Goods> doFindGoods(){
        return goodsService.findGoods();
    }
}
